home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 21 / GetCodecInfoApp ƒ / GetCodecInfoApp.c next >
Encoding:
C/C++ Source or Header  |  1997-02-26  |  20.5 KB  |  690 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        GetCodecInfoApp.c
  3.     
  4.     Contains:    Code for develop column .
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        11/01/94    JW        New.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    "SpinCursor.h"
  23. #include    "GetCodecInfoApp.h"
  24.  
  25. #ifdef powerc
  26. QDGlobals        qd;
  27. #endif
  28.  
  29. short                gRefNum;
  30. PicHandle            gPicture;
  31.  
  32. void main(void)
  33. {
  34.     OSErr                err;
  35.     long                vers;
  36.     StandardFileReply    myReply;
  37.     
  38.     //    Create a heap with lots of master pointers.
  39.     MaxApplZone();
  40.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  41.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  42.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  43.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  44.     
  45.     //    Initialize managers.
  46.     InitGraf(&qd.thePort);
  47.     FlushEvents(everyEvent, 0);
  48.     InitWindows();
  49.     InitDialogs(nil);
  50.     InitCursor();
  51.  
  52.     //    Require at least System 7.0 and Quicktime.
  53.     Gestalt(gestaltSystemVersion, &vers);
  54.     vers = (vers >> 8) & 0x0f;
  55.     if ( vers < 7 ) {
  56.         ReportWarning("\pThis Application requires System 7 or later!");
  57.         ExitToShell();
  58.     }
  59.     err = Gestalt(gestaltQuickTime, &vers);
  60.     if ( err != noErr ) {
  61.         ReportWarning("\pQuickTime is required.  Please install it and try again.");
  62.         ExitToShell();
  63.     }
  64.     err = EnterMovies();
  65.     if ( err != noErr ) {
  66.         ReportWarning("\pQuickTime is required.  Please install it and try again.");
  67.         ExitToShell();
  68.     }
  69.     
  70.     //    Initialize.
  71.     err = noErr;
  72.     gRefNum = -1;
  73.     gPicture = (PicHandle) NewHandle(4);
  74.     if ( gPicture != nil ) {
  75.         PicHandle            tempPicture;
  76.  
  77.         tempPicture = GetPicture(128);
  78.         if ( tempPicture != nil ) {
  79.             err = CompressPicture(tempPicture, gPicture, codecHighQuality, 0);
  80.             if ( err != noErr ) {
  81.                 ReportWarning("\pCould not create picture for testing codec speed.  (Not enough memory).");
  82.                 DisposeHandle((Handle) gPicture);
  83.                 gPicture = nil;
  84.             }
  85.             DisposeHandle((Handle) tempPicture);
  86.         } else {
  87.             ReportWarning("\pCould not find picture in resource id #128 for testing codec speed.");
  88.             DisposeHandle((Handle) gPicture);
  89.             gPicture = nil;
  90.         }
  91.     }
  92.     
  93.     //    Get file.
  94.     StandardPutFile("\pFile to save report to:", "\pCodecInfo Report", &myReply);
  95.     if (!(myReply.sfGood))
  96.         goto end;
  97.     
  98.     //    Create file.
  99.     err = FSpCreate(&(myReply.sfFile), 'ttxt', 'TEXT', smSystemScript);
  100.     if ( err != noErr ) {
  101.         FSpDelete(&(myReply.sfFile));
  102.         err = FSpCreate(&(myReply.sfFile), 'ttxt', 'TEXT', smSystemScript);
  103.         if ( err != noErr ) {
  104.             ReportWarning("\pCouldn't create file.");
  105.             goto end;
  106.         }
  107.     }
  108.  
  109.     //    Open output file
  110.     err = FSpOpenDF(&(myReply.sfFile), fsWrPerm, &gRefNum);
  111.     if ( err != noErr ) {
  112.         gRefNum = -1;
  113.         ReportWarning("\pCouldn't open file.");
  114.         goto end;
  115.     }
  116.     
  117.     //    Set beginning position
  118.     err = SetFPos(gRefNum, fsFromStart, 0);
  119.     if ( err != noErr ) {
  120.         ReportWarning("\pCouldn't set to beginning of file.");
  121.         goto end;
  122.     }
  123.  
  124.     //    Write something
  125.     ReportHeader();
  126.     ReportCodecList();
  127.  
  128.     //    Finish up.
  129. end:
  130.     if ( gRefNum != -1 )
  131.         FSClose(gRefNum);
  132.  
  133.     ExitToShell();
  134. }
  135.  
  136. /* ------------------------------------------------------------------------- */
  137.  
  138. void ReportWarning(Str255 theStr)
  139. {
  140.     short        itemHit;
  141.     DialogPtr    myDialog;
  142.     
  143.     ParamText("\pWARNING!", theStr, nil, nil);
  144.     myDialog = GetNewDialog(kDLOG_ERROR, 0, (WindowPtr) -1);
  145.     do {
  146.         ModalDialog(nil, &itemHit);
  147.     } while ( (itemHit != ok) );
  148.     DisposeDialog(myDialog);
  149. }
  150.  
  151. /* ------------------------------------------------------------------------- */
  152.  
  153. void WriteStr(Str255 str)
  154. {
  155.     long        count;
  156.     
  157.     count = str[0];
  158.     FSWrite(gRefNum, &count, (unsigned char *) &str[1]);
  159. }
  160.  
  161. void WriteBuf(unsigned char *str, long count)
  162. {
  163.     FSWrite(gRefNum, &count, (unsigned char *) str);
  164. }
  165.  
  166. void WriteReturn(void)
  167. {
  168.     long        count;
  169.     
  170.     count = 1;
  171.     FSWrite(gRefNum, &count, (unsigned char *) "\r");
  172. }
  173.  
  174. void WriteResourceStr(short id)
  175. {
  176.     Handle        str;
  177.     long        count;
  178.     char        state;
  179.     
  180.     str = Get1Resource('TEXT', id);
  181.     count = GetHandleSize(str);
  182.     
  183.     state = HGetState(str);
  184.     HLock(str);
  185.     FSWrite(gRefNum, &count, (unsigned char *) *str);
  186.     HSetState(str, state);
  187. }
  188.  
  189. /* ------------------------------------------------------------------------- */
  190.  
  191. void ReportHeader(void)
  192. {
  193.     WriteResourceStr(kSTR_INTRO);
  194.     WriteResourceStr(kSTR_COMPRESS);
  195.     WriteResourceStr(kSTR_DECOMPRESS);
  196. }
  197.  
  198. void ReportCodecList(void)
  199. {
  200.     OSErr                    err;
  201.     ComponentDescription    desc, foundComp;
  202.     Component                comp;
  203.     ComponentInstance        compinst;
  204.     CodecInfo                info;
  205.     short                    i;
  206.     
  207.     
  208.     //    Find compressors.
  209.     desc.componentType = compressorComponentType;
  210.     desc.componentSubType = 0;
  211.     desc.componentManufacturer = 0;
  212.     desc.componentFlags = 0;
  213.     desc.componentFlagsMask = 0;
  214.     comp = 0;
  215.     
  216.     do {
  217.         comp = FindNextComponent(comp, &desc);
  218.         if ( comp != nil ) {
  219.             GetComponentInfo(comp, &foundComp, nil, nil, nil);
  220.             compinst = OpenComponent(comp);
  221.             if ( compinst != 0 ) {
  222.                 CallGetCodecInfo(compinst, &info);
  223.                 ReportCompressor(&info);
  224.                 ReportCompressorSpeed(foundComp.componentSubType);
  225.                 WriteReturn();
  226.                 CloseComponent(compinst);
  227.             }
  228.         }
  229.     } while ( comp != nil );
  230.     
  231.     WriteReturn();
  232.     
  233.     //    Find compressors.
  234.     desc.componentType = decompressorComponentType;
  235.     desc.componentSubType = 0;
  236.     desc.componentManufacturer = 0;
  237.     desc.componentFlags = 0;
  238.     desc.componentFlagsMask = 0;
  239.     comp = 0;
  240.     
  241.     do {
  242.         comp = FindNextComponent(comp, &desc);
  243.         if ( comp != nil ) {
  244.             GetComponentInfo(comp, &foundComp, nil, nil, nil);
  245.             compinst = OpenComponent(comp);
  246.             if ( compinst != 0 ) {
  247.                 CallGetCodecInfo(compinst, &info);
  248.                 ReportDecompressor(&info);
  249.                 ReportDecompressorSpeed(foundComp.componentSubType);
  250.                 WriteReturn();
  251.                 CloseComponent(compinst);
  252.             }
  253.         }
  254.     } while ( comp != nil );
  255. }
  256.  
  257. void ReportCompressor(CodecInfo *info)
  258. {
  259.     Str255        str;
  260.     
  261.     WriteStr("\pCompressor Name: ");
  262.     WriteStr(info->typeName);
  263.     WriteStr("\p\r------------------------------------\r");
  264.     
  265.     WriteStr("\p   - version = ");
  266.     NumToString((long) info->version, str);
  267.     WriteStr(str);
  268.     WriteReturn();
  269.     
  270.     WriteStr("\p   - revisionLevel = ");
  271.     NumToString((long) info->revisionLevel, str);
  272.     WriteStr(str);
  273.     WriteReturn();
  274.     
  275.     WriteStr("\p   - vendor = ");
  276.     WriteBuf((unsigned char *) &(info->vendor), 4);
  277.     WriteReturn();
  278.     
  279.     WriteStr("\p   - compressionAccuracy = ");
  280.     NumToString((long) info->compressionAccuracy, str);
  281.     WriteStr(str);
  282.     WriteReturn();
  283.  
  284.     WriteStr("\p   - compressionSpeed = ");
  285.     NumToString((long) info->compressionSpeed, str);
  286.     WriteStr(str);
  287.     WriteReturn();
  288.  
  289.     WriteStr("\p   - compressionLevel = ");
  290.     NumToString((long) info->compressionLevel, str);
  291.     WriteStr(str);
  292.     WriteReturn();
  293.     
  294.     WriteStr("\p   - minimum height = ");
  295.     NumToString((long) info->minimumHeight, str);
  296.     WriteStr(str);
  297.     WriteReturn();
  298.  
  299.     WriteStr("\p   - minimum width = ");
  300.     NumToString((long) info->minimumWidth, str);
  301.     WriteStr(str);
  302.     WriteReturn();
  303.  
  304.     WriteStr("\p   - compress pipeline latency = ");
  305.     NumToString((long) info->compressPipelineLatency, str);
  306.     WriteStr(str);
  307.     WriteReturn();
  308.  
  309.     WriteStr("\p   - compression capabilities:\r");
  310.     if ( info->compressFlags & codecInfoDoes1 )
  311.         WriteStr("\p         directly compresses 1-bit pixels maps\r");
  312.     if ( info->compressFlags & codecInfoDoes2 )
  313.         WriteStr("\p         directly compresses 2-bit pixels maps\r");
  314.     if ( info->compressFlags & codecInfoDoes4 )
  315.         WriteStr("\p         directly compresses 4-bit pixels maps\r");
  316.     if ( info->compressFlags & codecInfoDoes8 )
  317.         WriteStr("\p         directly compresses 8-bit pixels maps\r");
  318.     if ( info->compressFlags & codecInfoDoes16 )
  319.         WriteStr("\p         directly compresses 16-bit pixels maps\r");
  320.     if ( info->compressFlags & codecInfoDoes32 )
  321.         WriteStr("\p         directly compresses 32-bit pixels maps\r");
  322.     if ( info->compressFlags & codecInfoDoesDither )
  323.         WriteStr("\p         supports fast dithering\r");
  324.     if ( info->compressFlags & codecInfoDoesStretch )
  325.         WriteStr("\p         can stretch to arbitrary sizes in codec\r");
  326.     if ( info->compressFlags & codecInfoDoesShrink )
  327.         WriteStr("\p         can shrink to arbitrary sizes in codec\r");
  328.     if ( info->compressFlags & codecInfoDoesMask )
  329.         WriteStr("\p         supports clipping regions\r");
  330.     if ( info->compressFlags & codecInfoDoesTemporal )
  331.         WriteStr("\p         supports temporal compression\r");
  332.     if ( info->compressFlags & codecInfoDoesDouble )
  333.         WriteStr("\p         can stretch to double size\r");
  334.     if ( info->compressFlags & codecInfoDoesQuad )
  335.         WriteStr("\p         can stretch to quad size\r");
  336.     if ( info->compressFlags & codecInfoDoesHalf )
  337.         WriteStr("\p         can shrink to half size\r");
  338.     if ( info->compressFlags & codecInfoDoesQuarter )
  339.         WriteStr("\p         can shrink to quarter size\r");
  340.     if ( info->compressFlags & codecInfoDoesRotate )
  341.         WriteStr("\p         can rotate\r");
  342.     if ( info->compressFlags & codecInfoDoesHorizFlip )
  343.         WriteStr("\p         can flip horizontally\r");
  344.     if ( info->compressFlags & codecInfoDoesVertFlip )
  345.         WriteStr("\p         can flip vertically\r");
  346.     if ( info->compressFlags & codecInfoDoesSkew )
  347.         WriteStr("\p         can skew image\r");
  348.     if ( info->compressFlags & codecInfoDoesBlend )
  349.         WriteStr("\p         can blend image with matte\r");
  350.     if ( info->compressFlags & codecInfoDoesWarp )
  351.         WriteStr("\p         can warp image arbitrarily\r");
  352.     if ( info->compressFlags & codecInfoDoesRecompress )
  353.         WriteStr("\p         can recompresses images without accumulating errors\r");
  354.     if ( info->compressFlags & codecInfoDoesSpool )
  355.         WriteStr("\p         can use data-loading or unloading function\r");
  356.     if ( info->compressFlags & codecInfoDoesRateConstrain )
  357.         WriteStr("\p         can rate constrain to caller defined limit\r");
  358.  
  359.     WriteStr("\p   - compression format:\r");
  360.     if ( info->formatFlags & codecInfoDepth1 )
  361.         WriteStr("\p         can store images in 1-bit color\r");
  362.     if ( info->formatFlags & codecInfoDepth2 )
  363.         WriteStr("\p         can store images in 2-bit color\r");
  364.     if ( info->formatFlags & codecInfoDepth4 )
  365.         WriteStr("\p         can store images in 4-bit color\r");
  366.     if ( info->formatFlags & codecInfoDepth8 )
  367.         WriteStr("\p         can store images in 8-bit color\r");
  368.     if ( info->formatFlags & codecInfoDepth16 )
  369.         WriteStr("\p         can store images in 16-bit color\r");
  370.     if ( info->formatFlags & codecInfoDepth24 )
  371.         WriteStr("\p         can store images in 24-bit color\r");
  372.     if ( info->formatFlags & codecInfoDepth32 )
  373.         WriteStr("\p         can store images in 32-bit color\r");
  374.     if ( info->formatFlags & codecInfoDepth33 )
  375.         WriteStr("\p         can store images in 1-bit monochrome\r");
  376.     if ( info->formatFlags & codecInfoDepth34 )
  377.         WriteStr("\p         can store images in 2-bit grayscale\r");
  378.     if ( info->formatFlags & codecInfoDepth36 )
  379.         WriteStr("\p         can store images in 4-bit grayscale\r");
  380.     if ( info->formatFlags & codecInfoDepth40 )
  381.         WriteStr("\p         can store images in 8-bit grayscale\r");
  382.     if ( info->formatFlags & codecInfoStoresClut )
  383.         WriteStr("\p         can store custom color table\r");
  384.     if ( info->formatFlags & codecInfoDoesLossless )
  385.         WriteStr("\p         can store in lossless format\r");
  386.     if ( info->formatFlags & codecInfoSequenceSensitive ) {
  387.         WriteStr("\p         compressed data requires non-key frames to be decompressed\r");
  388.         WriteStr("\p            in same order as compressed\r");
  389.     }
  390. }
  391.  
  392. void ReportDecompressor(CodecInfo *info)
  393. {
  394.     Str255        str;
  395.     
  396.     WriteStr("\pDecompressor Name: ");
  397.     WriteStr(info->typeName);
  398.     WriteStr("\p\r------------------------------------\r");
  399.     
  400.     WriteStr("\p   - version = ");
  401.     NumToString((long) info->version, str);
  402.     WriteStr(str);
  403.     WriteReturn();
  404.     
  405.     WriteStr("\p   - revisionLevel = ");
  406.     NumToString((long) info->revisionLevel, str);
  407.     WriteStr(str);
  408.     WriteReturn();
  409.     
  410.     WriteStr("\p   - vendor = ");
  411.     WriteBuf((unsigned char *) &(info->vendor), 4);
  412.     WriteReturn();
  413.     
  414.     WriteStr("\p   - decompressionAccuracy = ");
  415.     NumToString((long) info->decompressionAccuracy, str);
  416.     WriteStr(str);
  417.     WriteReturn();
  418.  
  419.     WriteStr("\p   - decompressionSpeed = ");
  420.     NumToString((long) info->decompressionSpeed, str);
  421.     WriteStr(str);
  422.     WriteReturn();
  423.  
  424.     WriteStr("\p   - minimum height = ");
  425.     NumToString((long) info->minimumHeight, str);
  426.     WriteStr(str);
  427.     WriteReturn();
  428.  
  429.     WriteStr("\p   - minimum width = ");
  430.     NumToString((long) info->minimumWidth, str);
  431.     WriteStr(str);
  432.     WriteReturn();
  433.  
  434.     WriteStr("\p   - decompress pipeline latency = ");
  435.     NumToString((long) info->decompressPipelineLatency, str);
  436.     WriteStr(str);
  437.     WriteReturn();
  438.  
  439.     WriteStr("\p   - decompression capabilities:\r");
  440.     if ( info->compressFlags & codecInfoDoes1 )
  441.         WriteStr("\p         directly decompresses into 1-bit pixels maps\r");
  442.     if ( info->compressFlags & codecInfoDoes2 )
  443.         WriteStr("\p         directly decompresses into 2-bit pixels maps\r");
  444.     if ( info->compressFlags & codecInfoDoes4 )
  445.         WriteStr("\p         directly decompresses into 4-bit pixels maps\r");
  446.     if ( info->compressFlags & codecInfoDoes8 )
  447.         WriteStr("\p         directly decompresses into 8-bit pixels maps\r");
  448.     if ( info->compressFlags & codecInfoDoes16 )
  449.         WriteStr("\p         directly decompresses into 16-bit pixels maps\r");
  450.     if ( info->compressFlags & codecInfoDoes32 )
  451.         WriteStr("\p         directly decompresses into 32-bit pixels maps\r");
  452.     if ( info->compressFlags & codecInfoDoesDither )
  453.         WriteStr("\p         supports fast dithering\r");
  454.     if ( info->compressFlags & codecInfoDoesStretch )
  455.         WriteStr("\p         can stretch to arbitrary sizes in codec\r");
  456.     if ( info->compressFlags & codecInfoDoesShrink )
  457.         WriteStr("\p         can shrink to arbitrary sizes in codec\r");
  458.     if ( info->compressFlags & codecInfoDoesMask )
  459.         WriteStr("\p         supports clipping regions\r");
  460.     if ( info->compressFlags & codecInfoDoesTemporal )
  461.         WriteStr("\p         supports temporal compression\r");
  462.     if ( info->compressFlags & codecInfoDoesDouble )
  463.         WriteStr("\p         can stretch to double size\r");
  464.     if ( info->compressFlags & codecInfoDoesQuad )
  465.         WriteStr("\p         can stretch to quad size\r");
  466.     if ( info->compressFlags & codecInfoDoesHalf )
  467.         WriteStr("\p         can shrink to half size\r");
  468.     if ( info->compressFlags & codecInfoDoesQuarter )
  469.         WriteStr("\p         can shrink to quarter size\r");
  470.     if ( info->compressFlags & codecInfoDoesRotate )
  471.         WriteStr("\p         can rotate\r");
  472.     if ( info->compressFlags & codecInfoDoesHorizFlip )
  473.         WriteStr("\p         can flip horizontally\r");
  474.     if ( info->compressFlags & codecInfoDoesVertFlip )
  475.         WriteStr("\p         can flip vertically\r");
  476.     if ( info->compressFlags & codecInfoDoesSkew )
  477.         WriteStr("\p         can skew image\r");
  478.     if ( info->compressFlags & codecInfoDoesBlend )
  479.         WriteStr("\p         can blend image with matte\r");
  480.     if ( info->compressFlags & codecInfoDoesWarp )
  481.         WriteStr("\p         can warp image arbitrarily\r");
  482.     if ( info->compressFlags & codecInfoDoesRecompress )
  483.         WriteStr("\p         can recompress images without accumulating errors\r");
  484.     if ( info->compressFlags & codecInfoDoesSpool )
  485.         WriteStr("\p         can use data-loading or unloading function\r");
  486.     if ( info->compressFlags & codecInfoDoesRateConstrain )
  487.         WriteStr("\p         can rate contrain to caller defined limit\r");
  488.  
  489.     WriteStr("\p   - decompression format:\r");
  490.     if ( info->formatFlags & codecInfoDepth1 )
  491.         WriteStr("\p         can decompress images from 1-bit color compressed format\r");
  492.     if ( info->formatFlags & codecInfoDepth2 )
  493.         WriteStr("\p         can decompress images from 2-bit color compressed format\r");
  494.     if ( info->formatFlags & codecInfoDepth4 )
  495.         WriteStr("\p         can decompress images from 4-bit color compressed format\r");
  496.     if ( info->formatFlags & codecInfoDepth8 )
  497.         WriteStr("\p         can decompress images from 8-bit color compressed format\r");
  498.     if ( info->formatFlags & codecInfoDepth16 )
  499.         WriteStr("\p         can decompress images from 16-bit color compressed format\r");
  500.     if ( info->formatFlags & codecInfoDepth24 )
  501.         WriteStr("\p         can decompress images from 24-bit color compressed format\r");
  502.     if ( info->formatFlags & codecInfoDepth32 )
  503.         WriteStr("\p         can decompress images from 32-bit color compressed format\r");
  504.     if ( info->formatFlags & codecInfoDepth33 )
  505.         WriteStr("\p         can decompress images from 1-bit monochrome compressed format\r");
  506.     if ( info->formatFlags & codecInfoDepth34 )
  507.         WriteStr("\p         can decompress images from 2-bit grayscale compressed format\r");
  508.     if ( info->formatFlags & codecInfoDepth36 )
  509.         WriteStr("\p         can decompress images from 4-bit grayscale compressed format\r");
  510.     if ( info->formatFlags & codecInfoDepth40 )
  511.         WriteStr("\p         can decompress images from 8-bit grayscale compressed format\r");
  512.     if ( info->formatFlags & codecInfoStoresClut )
  513.         WriteStr("\p         can store custom color table\r");
  514.     if ( info->formatFlags & codecInfoDoesLossless )
  515.         WriteStr("\p         can store in lossless format\r");
  516.     if ( info->formatFlags & codecInfoSequenceSensitive ) {
  517.         WriteStr("\p         compressed data requires non-key frames to be decompressed\r");
  518.         WriteStr("\p            in same order as compressed\r");
  519.     }
  520. }
  521.  
  522. void ReportCompressorSpeed(OSType type)
  523. {
  524.     OSErr                    err;
  525.     Str255                    str;
  526.     PicHandle                tempPicture;
  527.     long                    begin, end, times;
  528.     Boolean                    failed;
  529.     GWorldPtr                gworld;
  530.     CGrafPtr                saveport;
  531.     GDHandle                savegdevice;
  532.     Rect                    myRect = {0, 0, 480, 640};
  533.     Boolean                    animCur;
  534.     
  535.     //    Initialize.
  536.     gworld = nil;
  537.     
  538.     if ( gPicture == nil )
  539.         return;
  540.     
  541.     animCur = InitAnimatedCursors(beachBall, 0);
  542.  
  543.     if ( animCur )
  544.         SpinCursor();
  545.     
  546.     failed = false;
  547.     GetGWorld(&saveport, &savegdevice);
  548.     err = NewGWorld(&gworld, 32, &myRect, nil, nil, 0);
  549.     if ( err == noErr ) {
  550.         PixMapHandle            pmap;
  551.         ImageDescriptionHandle    desc;
  552.         long                    size;
  553.         Ptr                        data;
  554.         
  555.         if ( animCur )
  556.             SpinCursor();
  557.         SetGWorld(gworld, nil);
  558.         LockPixels(GetGWorldPixMap(gworld));
  559.         pmap = GetGWorldPixMap(gworld);
  560.         EraseRect(&myRect);
  561.         DrawPicture(gPicture, &myRect);
  562.         desc = (ImageDescriptionHandle) NewHandle(4);
  563.         if ( desc != nil ) {
  564.             err = GetMaxCompressionSize(pmap, &myRect, 32, codecHighQuality, type, anyCodec, &size);
  565.             if ( err == noErr ) {
  566.                 begin = TickCount();
  567.                 for ( times = 10; times > 0; times-- ) {
  568.                     data = NewPtr(size);
  569.                     if ( data != nil ) {
  570.                         err = CompressImage(pmap, &myRect, codecHighQuality, type, desc, data);
  571.                         if ( err != noErr )
  572.                             failed = true;
  573.                         if ( animCur )
  574.                             SpinCursor();
  575.                         DisposePtr(data);
  576.                     } else
  577.                         failed = true;
  578.                 }
  579.                 end = TickCount();
  580.             } else
  581.                 failed = true;
  582.             DisposeHandle((Handle) desc);
  583.         } else
  584.             failed = true;
  585.         DisposeGWorld(gworld);
  586.     } else
  587.         failed = true;
  588.     SetGWorld(saveport, savegdevice);
  589.     
  590.     if ( animCur )
  591.         ReleaseAnimatedCursors();
  592.  
  593.     if ( failed ) {
  594.         WriteStr("\p   - estimated decompression speed:\r");
  595.         WriteStr("\p      - test failed\r");
  596.     } else {
  597.         WriteStr("\p   - estimated decompression speed:\r");
  598.         WriteStr("\p         640x480 32 bit RGB = ");
  599.         NumToString((long) (((end - begin)*1000)/600), str);
  600.         WriteStr(str);
  601.         WriteStr("\p milliseconds\r");
  602.     }
  603. }
  604.  
  605. void ReportDecompressorSpeed(OSType type)
  606. {
  607.     OSErr                    err;
  608.     Str255                    str;
  609.     PicHandle                tempPicture;
  610.     long                    begin, end, times;
  611.     Boolean                    failed;
  612.     GWorldPtr                gworld;
  613.     CGrafPtr                saveport;
  614.     GDHandle                savegdevice;
  615.     Rect                    myRect = {0, 0, 480, 640};
  616.     Boolean                    animCur;
  617.     
  618.     //    Initialize.
  619.     gworld = nil;
  620.     
  621.     if ( gPicture == nil )
  622.         return;
  623.     
  624.     animCur = InitAnimatedCursors(beachBall, 0);
  625.  
  626.     if ( animCur )
  627.         SpinCursor();
  628.     
  629.     failed = false;
  630.     GetGWorld(&saveport, &savegdevice);
  631.     err = NewGWorld(&gworld, 32, &myRect, nil, nil, 0);
  632.     if ( err == noErr ) {
  633.         PixMapHandle            pmap;
  634.         ImageDescriptionHandle    desc;
  635.         long                    size;
  636.         Ptr                        data;
  637.         
  638.         if ( animCur )
  639.             SpinCursor();
  640.         SetGWorld(gworld, nil);
  641.         LockPixels(GetGWorldPixMap(gworld));
  642.         pmap = GetGWorldPixMap(gworld);
  643.         EraseRect(&myRect);
  644.         DrawPicture(gPicture, &myRect);
  645.         desc = (ImageDescriptionHandle) NewHandle(4);
  646.         if ( desc != nil ) {
  647.             err = GetMaxCompressionSize(pmap, &myRect, 32, codecHighQuality, type, anyCodec, &size);
  648.             if ( err == noErr ) {
  649.                 data = NewPtr(size);
  650.                 if ( data != nil ) {
  651.                     err = CompressImage(pmap, &myRect, codecHighQuality, type, desc, data);
  652.                     if ( err == noErr ) {
  653.                         begin = TickCount();
  654.                         for ( times = 10; times > 0; times-- ) {
  655.                             if ( animCur )
  656.                                 SpinCursor();
  657.                             err = DecompressImage(data, desc, pmap, &myRect, &myRect, srcCopy, nil);
  658.                             if ( err != nil )
  659.                                 failed = true;
  660.                         }
  661.                         end = TickCount();
  662.                     } else
  663.                         failed = true;
  664.                     DisposePtr(data);
  665.                 } else
  666.                     failed = true;
  667.             } else
  668.                 failed = true;
  669.             DisposeHandle((Handle) desc);
  670.         } else
  671.             failed = true;
  672.         DisposeGWorld(gworld);
  673.     } else
  674.         failed = true;
  675.     SetGWorld(saveport, savegdevice);
  676.     
  677.     if ( animCur )
  678.         ReleaseAnimatedCursors();
  679.  
  680.     if ( failed ) {
  681.         WriteStr("\p   - estimated compression speed:\r");
  682.         WriteStr("\p      - test failed\r");
  683.     } else {
  684.         WriteStr("\p   - estimated compression speed:\r");
  685.         WriteStr("\p         640x480 32 bit RGB = ");
  686.         NumToString((long) (((end - begin)*1000)/600), str);
  687.         WriteStr(str);
  688.         WriteStr("\p milliseconds\r");
  689.     }
  690. }